<?php
namespace app\index\controller;

use think\View;

class Product extends CheckMember
{
    /**
     * 就行酒柜
     * @return \think\response\View
     */
    public function index()
    {
        $param = input('param.');

        // 获取店铺分类
        $data = $this->local_invoke_api('get_shop_category', ['id' => $param['shop_id']]);
        $this->assign('data', $data['data']);

        $this->assign('param', $param);
        return view();
    }

    /**
     * 获取产品列表
     * @return \think\response\Json
     */
    public function get_product_list() {
        $param = input('param.');
        $param['page_type'] = 2;
        $data = $this->local_invoke_api('get_shop_product_list', $param);
        $view = new View();
        $view->assign('data', $data['data']);
        $view->assign('shop_id', $param['shop_id']);
        $tpl = $view->fetch('product_list_tpl');
        $data['tpl'] = $tpl;
        return json($data);
    }

    /**
     * 产品详情
     * @return \think\response\View
     */
    public function info() {
        $param = input('param.');
        $data = $this->local_invoke_api('get_shop_product_info', $param);
        $this->assign('data', $data['data']);
        $this->assign('id', $param['id']);
        $this->assign('shop_id', $param['shop_id']);
        return view();
    }

    /**
     * 获取产品评论
     * @return \think\response\Json
     */
    public function get_comment() {
        $param = input('param.');
        $data = $this->local_invoke_api('get_comment_by_shop_and_product', $param);
        $view = new View();
        $view->assign('data', $data['data']);
        $tpl = $view->fetch('comment_list_tpl');
        $data['tpl'] = $tpl;
        return json($data);
    }
}
